import { IClientVm, IConfig, IDoctor, IPatient, IPersonalInfo, IRoom } from '@/interface/common'
import { IAddCreditQuery, IReservationListResponseData, ISysPay } from '@/views/reservation/interface/reservation'
import { IReservationInspection } from '@/views/inspection/interface/inspection'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export interface IRootState {
  client : IClientVm
  config : IConfig
  showLoading: boolean
  showMessageBox: boolean
  isBusy: boolean
  showWindow: boolean
  loadingTitle: string
  bizType: '查询' | '充值' | '缴费' | '建档' | '签到' | undefined | '挂号'
  cardType: '身份证' | '医保卡' | undefined
  tip: string
  time: number
  maxTime: number
  personalInfo: IPersonalInfo
  patient: IPatient | undefined
  room: IRoom | undefined
  doctor: IDoctor | undefined
  AddCreditQuery: IAddCreditQuery
  AddCreditPay: ISysPay
  InspectionList: IReservationInspection[]
  Inspection?: IReservationInspection
  InHosNo?: string
  reservationList: IReservationListResponseData[]
}

export default new Vuex.Store<IRootState>({
  mutations: {
    showLoading (state, title = '加载中...') {
      state.showLoading = true
      state.loadingTitle = title
    },
    hideLoading (state) {
      state.showLoading = false
    },
    showWindow (state) {
      state.showWindow = true
    },
    hideWindow (state) {
      state.showWindow = false
    },
    setBusy (state, isBusy: boolean) {
      state.isBusy = isBusy
    },
    updateClient (state, client:IClientVm) {
      state.client = client
    },
    updateConfig (state, config: IConfig) {
      state.config = config
    },
    updateTip (state, tip: string) {
      state.tip = tip
    },
    updateTime (state, time: number) {
      state.time = time
    },
    updateMaxTime (state, time: number) {
      state.maxTime = time
    },
    updatePersonalInfo (state, info: IPersonalInfo) {
      state.personalInfo = info
    },
    updatePatient (state, info: IPatient) {
      state.patient = info
    },
    updateRoom (state, info: IRoom) {
      state.room = info
    },
    updateInHosNo (state, info: string | undefined) {
      state.InHosNo = info
    },
    updateReservationList (state, info: IReservationListResponseData[]) {
      try {
        state.reservationList.splice(0)
      } catch (error) {

      }
      state.reservationList = []
      for (let i = 0; i < info.length; i++) {
        const element = info[i]
        state.reservationList.push(element)
        Vue.set(state.reservationList, i, element)
      }
    }
  }
})
